package br.ufrn.cep.eEtica.negocio.rest;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import br.ufrn.cep.eEtica.integracao.model.Instituicao;

@Path("/instituicao/")
public class IntituicaoWS extends GenericRS<Instituicao>{

	
	/**
	 *  /instituicao
	 * 
	 * @param id
	 * @return <Instituicao>
	 */
	@Override
	@GET
	@Produces(MediaType.TEXT_XML)
	public Instituicao getById(@QueryParam("id") int id){
		return getDao().findById(Instituicao.class, id);
	}

	/**
	 *  /instituicao/listar
	 *  
	 *  @return List<Instituicao>
	 */
	@Override
	@GET 
	@Path("/listar/")
	@Produces(MediaType.TEXT_XML)
	public List<Instituicao> list() {
		return getDao().find(Instituicao.class);
	}


	@Override
	@POST
	@Path("/cadastrar/")
	@Produces(MediaType.TEXT_XML)
	@Consumes(MediaType.TEXT_XML)
	public Instituicao create(Instituicao element) {
		getDao().persist(element);
		return element;
	}

	
	@Override
	@PUT
	@Path("/atualizar/")
	@Produces(MediaType.TEXT_XML)
	@Consumes(MediaType.TEXT_XML)
	public Instituicao update(Instituicao element) {
		getDao().merge(element);
		return element;
	}
	
	/**
	 *  /instituicao/remover
	 * 
	 * @param id
	 */
	@Override
	@DELETE
	@Path("/remover/")
	public void delete(@QueryParam("id")int id) {
		getDao().deleteById(Instituicao.class, id);
	}
	
	
}
